<?php
/*
 * @Author: your name
 * @Date: 2021-12-07 09:50:02
 * @LastEditTime: 2022-03-10 20:58:21
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \property\app\Http\Controllers\find_shop\User.php
 */

namespace App\Http\Controllers\find_shop;

use Illuminate\Support\Facades\Request;
// use  App\Http\Controllers\redis\RedisController as Redis;
use  App\Models\admin_model\Housing as HousingDb;
use  App\Models\admin_model\TowerBuilding as TowerBuildingDb;

class Housing extends BaseController
{

    public function housingList()
    {

        // $whereStr = '';
        $limitStr = '';
        if (Request::input('pageSize') && Request::input('page')) {
            $limitStr =   limit_joint(Request::input('page'), Request::input('pageSize'));
        }
        // $keyWord = array_filter(Request::input('keyWord'), 'filtrfunction');
        // if (!empty($keyWord)) {
        //     $whereStr .= havaWhereLikeJoinEqual($keyWord);
        // }
        if (Request::has('keyWord')) {
            $whereStr = mysql_or_and(Request::input('keyWord'));
        }
        $list  =   housingDb::housingWebList($whereStr, $limitStr);
        return $this->create(200, '查询成功', $list);
        // } else {
        //     return missingParameter();
        // }
    }

    public function housingBuildingList()
    {
        $whereStr = '';
        $limitStr = '';

        if (Request::input('pageSize') && Request::input('page')) {
            $limitStr =   limit_joint(Request::input('page'), Request::input('pageSize'));
        }
        if (Request::has('keyWord')) {

            $keyWord = array_filter(Request::input('keyWord'), 'filtrfunction');
            if (!empty($keyWord)) {
                $whereStr .= havaWhereLikeJoinEqual($keyWord);
            }
        }
        $list  =   housingDb::housingWebList($whereStr, $limitStr);
        return $this->create(200, '查询成功', $list);
        // } else {
        //     return missingParameter();
        // }
    }

    public function housingSelOne()
    {
        if (Request::has('id')) {
            $id = Request::input('id');
            $user =  new User;
            $res =   $user->checkToken(false) ? HousingDb::housingWebSelOneCollect($id, $this->getLoginMsg()) : HousingDb::housingWebSelOne($id);
            if ($res) {
                return $this->create(200, '查询成功', $res[0]);
            }
        }
    }

    public function belongsBuilding()
    {
        if (Request::has('id')) {
            $id = Request::input('id');
            $res = TowerBuildingDb::buildingWebSelOneContent($id);
            if ($res) {
                return $this->create(200, '查询成功', $res[0]);
            }
        }
    }


    public function housingWebListRand()
    {
        if (Request::has('limit') && Request::has('id')) {

            return $this->create(200, '查询成功', HousingDb::housingWebListRand(Request::input('id'), Request::input('limit')));
        }
    }

    public function housingStoreList()
    {
        if (Request::has('admin_id')) {
            $admin_id = Request::input('admin_id');
            $limitStr = '';
            if (Request::has('pageSize') && Request::has('page')) {
                $limitStr =   limit_joint(Request::input('page'), Request::input('pageSize'));
            }
            return $this->create(200, '查询成功',  HousingDb::housingStoreList($admin_id, $limitStr));
        }
    }
}
